package com.fary.nio;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

/**
 * @author Fary
 * @version 1.0
 * @description: TODO
 * @date 2022/1/17 17:21
 */
public class ByteBuffer01 {

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(1024);

        // 这种方式是直接分配内存，与操作系统的耦合性更高，速度比上面的要更快，但是分配的开销更大
        ByteBuffer byteBuffer1 = ByteBuffer.allocateDirect(1024);

        byte[] bytes = new byte[]{12, 34, 56};
        ByteBuffer byteBuffer2 = ByteBuffer.wrap(bytes);

        IntBuffer intBuffer = byteBuffer1.asIntBuffer();
    }
}
